#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import socket
import subprocess

server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ip_port = ("127.0.0.1", 2004)
server.bind(ip_port)

while True:
    data, addr = server.recvfrom(1024)
    res = subprocess.Popen("{}".format(data.decode("utf-8")), shell=True,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)

    server.sendto(res.stdout.read().decode("gbk").encode("utf-8"), addr)
